﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Flexibles.CApCableParametersPointCloudUserControl
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Markup;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui.WPF;
using UiInternalControls.WPFControls;


namespace DnProcessSimulateCommands.Flexibles;

public class CApCableParametersPointCloudUserControl : UserControl, IComponentConnector
{
  private const double ParameterEpsilon = 0.0001;
  private bool m_isControlLoading;
  internal StackPanel pointCloudparameterStackPanel;
  internal Grid parameterGrid;
  internal RowDefinition length;
  internal RowDefinition radius;
  internal RowDefinition youngmodulus;
  internal RowDefinition density;
  internal RowDefinition fulcrum;
  internal ToggleButton toggleButtonLockLength;
  internal TextBlock textblockLength;
  internal TxNumericEditBoxControl TxNumericEditBoxLength;
  internal ToggleButton toggleButtonLockRadius;
  internal TextBlock textblockRadius;
  internal TxNumericEditBoxControl TxNumericEditBoxRadius;
  internal ToggleButton toggleButtonLockYoungModulus;
  internal TextBlock textblockYoungModulus;
  internal TxNumericEditBoxControl TxNumericEditBoxYoungsModulus;
  internal TxInfoButton TxInfoButtonStartEndFulcrum;
  internal TextBlock textblockDensity;
  internal TxNumericEditBoxControl TxNumericEditBoxDensity;
  internal TextBlock textblockFulcrum;
  internal TxNumericEditBoxControl TxNumericEditBoxFulcrum;
  private bool _contentLoaded;

  public CApCableParametersPointCloudUserControl() => this.m_isControlLoading = true;

  public CApFLEXCableNewAttributeViewModel AttributeViewModel { get; private set; }

  public CApCableParametersPointCloudUserControlViewModel ControlViewModel { get; private set; }

  public void InitControl(
    CApFLEXCableNewAttributeViewModel attributeViewModel)
  {
    this.AttributeViewModel = attributeViewModel;
    this.ControlViewModel = new CApCableParametersPointCloudUserControlViewModel(attributeViewModel);
    this.InitializeComponent();
    TxApplication.Options.Units.LinearUnitsChanged += new TxUnitsOptions_LinearUnitsChangedEventHandler(this.Units_LinearUnitsChanged);
    this.AttributeViewModel.FulcrumStepSize = this.ComputeFulcrumStepSize();
    this.InitNumEditorControl();
    this.InitNumEditorControlWithoutUnitDecimalPlace();
  }

  private void InitNumEditorControl()
  {
    this.UpdateLinearUnitText();
    this.textblockYoungModulus.Text = $"{this.textblockYoungModulus.Text} ({CApFLEXStringTable.YoungsModulusUnit}):";
  }

  private void InitNumEditorControlWithoutUnitDecimalPlace()
  {
    this.TxNumericEditBoxYoungsModulus.DecimalPlaces = 2;
    this.TxNumericEditBoxDensity.DecimalPlaces = 2;
    this.TxNumericEditBoxFulcrum.DecimalPlaces = 2;
  }

  public void UpdateLinearUnitText()
  {
    this.textblockLength.Text = CApFLEXStringTable.CableLengthLabel + CApCableUtility.LinearUnitLabelText();
    this.textblockRadius.Text = CApFLEXStringTable.CableRadiusLabel + CApCableUtility.LinearUnitLabelText();
  }

  private double ComputeFulcrumStepSize()
  {
    double fulcrumStepSize;
    switch ((int) TxApplication.Options.Units.LinearUnit)
    {
      case 0:
        fulcrumStepSize = 10.0;
        break;
      case 1:
        fulcrumStepSize = 1.0;
        break;
      case 2:
      case 3:
      case 4:
        fulcrumStepSize = 0.1;
        if (TxApplication.Options.Units.LinearDigitsAfterDecimalPoint == 0)
        {
          fulcrumStepSize = 1.0;
          break;
        }
        break;
      default:
        fulcrumStepSize = 1.0;
        break;
    }
    return fulcrumStepSize;
  }

  private void Units_LinearUnitsChanged(
    object sender,
    TxUnitsOptions_LinearUnitsChangedEventArgs args)
  {
    this.UpdateLinearUnitText();
  }

  public void DidDialogClose()
  {
    TxApplication.Options.Units.LinearUnitsChanged -= new TxUnitsOptions_LinearUnitsChangedEventHandler(this.Units_LinearUnitsChanged);
    this.ControlViewModel.Dispose();
  }

  private void TxNumericEditBoxLength_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.m_isControlLoading)
      return;
    this.AttributeViewModel.SetLengthNoEventSent(args.TentativeValue * TxApplication.Options.Units.LinearMultiplier);
  }

  private void TxNumericEditBoxRadius_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.m_isControlLoading)
      return;
    this.AttributeViewModel.SetRadiusNoEventSent(args.TentativeValue * TxApplication.Options.Units.LinearMultiplier);
  }

  private void TxNumericEditBoxYoungsModulus_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.m_isControlLoading)
      return;
    this.AttributeViewModel.SeYoungsModulusNoEventSent(args.TentativeValue);
  }

  private void TxNumericEditBoxDensity_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.m_isControlLoading)
      return;
    this.AttributeViewModel.SetDensityNoEventSent(args.TentativeValue);
  }

  private void TxNumericEditBoxFulcrum_TentativeValueChanged(
    object sender,
    TxNumericEditBoxCtrl_TentativeValueChangedEventArgs args)
  {
    if (this.m_isControlLoading)
      return;
    this.AttributeViewModel.SetFulcrumNoEventSent(args.TentativeValue * TxApplication.Options.Units.LinearMultiplier);
  }

  public void StartOfLoading() => this.m_isControlLoading = true;

  public void EndOfLoading() => this.m_isControlLoading = false;

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/flexibles/usercontrols/capcableparameterspointcloudusercontrol.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        this.pointCloudparameterStackPanel = (StackPanel) target;
        break;
      case 2:
        this.parameterGrid = (Grid) target;
        break;
      case 3:
        this.length = (RowDefinition) target;
        break;
      case 4:
        this.radius = (RowDefinition) target;
        break;
      case 5:
        this.youngmodulus = (RowDefinition) target;
        break;
      case 6:
        this.density = (RowDefinition) target;
        break;
      case 7:
        this.fulcrum = (RowDefinition) target;
        break;
      case 8:
        this.toggleButtonLockLength = (ToggleButton) target;
        break;
      case 9:
        this.textblockLength = (TextBlock) target;
        break;
      case 10:
        this.TxNumericEditBoxLength = (TxNumericEditBoxControl) target;
        this.TxNumericEditBoxLength.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxLength_TentativeValueChanged);
        break;
      case 11:
        this.toggleButtonLockRadius = (ToggleButton) target;
        break;
      case 12:
        this.textblockRadius = (TextBlock) target;
        break;
      case 13:
        this.TxNumericEditBoxRadius = (TxNumericEditBoxControl) target;
        this.TxNumericEditBoxRadius.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxRadius_TentativeValueChanged);
        break;
      case 14:
        this.toggleButtonLockYoungModulus = (ToggleButton) target;
        break;
      case 15:
        this.textblockYoungModulus = (TextBlock) target;
        break;
      case 16 /*0x10*/:
        this.TxNumericEditBoxYoungsModulus = (TxNumericEditBoxControl) target;
        this.TxNumericEditBoxYoungsModulus.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxYoungsModulus_TentativeValueChanged);
        break;
      case 17:
        this.TxInfoButtonStartEndFulcrum = (TxInfoButton) target;
        break;
      case 18:
        this.textblockDensity = (TextBlock) target;
        break;
      case 19:
        this.TxNumericEditBoxDensity = (TxNumericEditBoxControl) target;
        this.TxNumericEditBoxDensity.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxDensity_TentativeValueChanged);
        break;
      case 20:
        this.textblockFulcrum = (TextBlock) target;
        break;
      case 21:
        this.TxNumericEditBoxFulcrum = (TxNumericEditBoxControl) target;
        this.TxNumericEditBoxFulcrum.TentativeValueChanged += new TxNumericEditBoxCtrl_TentativeValueChangedEventHandler(this.TxNumericEditBoxFulcrum_TentativeValueChanged);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
